package com.wanmait.spacesys.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanmait.spacesys.dao.ConfigDAO;
import com.wanmait.spacesys.dao.ManagerinfoDAO;
import com.wanmait.spacesys.vo.Config;

/**
 * Servlet implementation class InitController
 */
@WebServlet(value="/InitController",loadOnStartup = 1)
public class InitController extends HttpServlet {
	private ConfigDAO configDAO = new ConfigDAO();
	private ManagerinfoDAO managerinfoDAO = new ManagerinfoDAO();
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		this.refresh();
	}
	private void refresh() {
		this.refreshConfig();
	}
	private void refreshConfig() {
		List<Config> configs = configDAO.findAll();
		Map<String,String> map = new HashMap<String,String>();
		for(Config config:configs) {
			map.put(config.getKey(), config.getValue());
			
		}
		this.getServletContext().setAttribute("configMap", map);
//		System.out.println(map);
		this.getServletContext().setAttribute("configList", configs);
		
	}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}



}
